package cn.coisini.controller.v1;

import cn.coisini.api.admin.TagControllerApi;
import cn.coisini.model.common.annotation.RedisAccessLimit;
import cn.coisini.model.common.dtos.Result;
import cn.coisini.model.common.enums.ResultEnum;
import cn.coisini.model.common.log.annotation.Log;
import cn.coisini.model.common.log.enums.BusinessType;
import cn.coisini.model.pojo.Tag;
import cn.coisini.model.vo.QueryVo;
import cn.coisini.model.vo.TagVo;
import cn.coisini.service.TagService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author xiangshaw
 * Description: 标签控制器
 */
@RestController
@RequiredArgsConstructor
public class TagController  implements TagControllerApi {

    private final TagService tagService;

    // 添加标签
    @Override
    @RedisAccessLimit(seconds = 60, maxCount = 30)
    @Log(title = "标签管理", businessType = BusinessType.INSERT)
    public Result<ResultEnum> addTag(TagVo tagVo) {
        return tagService.addTag(tagVo);
    }

    // 查询标签列表
    @Override
    @RedisAccessLimit(seconds = 60, maxCount = 30)
    public Result<Object> getTagList(QueryVo queryVo) {
        return tagService.getTagList(queryVo);
    }

    // 发布文章获取标签列表
    @Override
    @RedisAccessLimit(seconds = 60, maxCount = 30)
    public Result<List<Tag>> getTagList() {
        return tagService.getTagList();
    }

    // 修改标签
    @Override
    @RedisAccessLimit(seconds = 60, maxCount = 30)
    @Log(title = "标签管理", businessType = BusinessType.UPDATE)
    public Result<ResultEnum> updateTag(TagVo tagVo) {
        return tagService.updateTag(tagVo);
    }

    // 删除标签
    @Override
    @RedisAccessLimit(seconds = 60, maxCount = 30)
    @Log(title = "标签管理", businessType = BusinessType.DELETE)
    public Result<ResultEnum> deleteTag(TagVo tagVo) {
        return tagService.deleteTag(tagVo.getId());
    }

    // 批量删除标签
    @Override
    @RedisAccessLimit(seconds = 60, maxCount = 30)
    @Log(title = "标签管理", businessType = BusinessType.BATCH_REMOVE)
    public Result<ResultEnum> deleteTagByIds(TagVo tagVo) {
        return tagService.deleteTagByIds(tagVo.getIds());
    }
}
